﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ARR.Entities.ComponentModel;
using ARR.Entities.Validation;
using System.Runtime.Serialization;

namespace ARR.Entities
{
    public partial class Article
    {
        [DataMember]
        public RangeReview RangeReview { get; set; }

        [DataMember]
        public Category Category { get; set; }

        [DataMember]
        public Comment Comment { get; set; }

        [DataMember]
        public List<Entities.Attribute> Attributes { get; set; }

        //LG: Propiedades del Pareto
        [DataMember]
        public Nullable<int> Ranking { get; set; }

        [DataMember]
        public Nullable<int> RankingSort { get; set; }

        [DataMember]
        public bool IsSelected { get; set; }

        [DataMember]
        public decimal Units { get; set; }

        [DataMember]
        public decimal UnitsInCombos { get; set; }

        [DataMember]
        public decimal Sales { get; set; }

        [DataMember]
        public decimal Margin { get; set; }

        [DataMember]
        public decimal MarginP { get; set; }

        [DataMember]
        public decimal InventoryCost { get; set; }

        [DataMember]
        public decimal AcumSales { get; set; }

        [DataMember]
        public decimal AcumUnits { get; set; }

        [DataMember]
        public decimal AcumMargin { get; set; }

        [DataMember]
        public decimal PrevAcumSales { get; set; }

        [DataMember]
        public decimal AcumSKUs { get; set; }

        [DataMember]
        public decimal Coverage { get; set; }
        
        [DataMember]
        public decimal StoreCoverage { get; set; }

        [DataMember]
        public int StoreCoverageQuantity { get; set; }

        [DataMember]
        public decimal MonthsCoverage { get; set; }

        [DataMember]
        public int MonthsCoverageQuantity { get; set; }

        [DataMember]
        public UnitOfMeasureConvertion UomConversion { get; set; }

        [DataMember]
        public string CategoryCode { get; set; }


        public string CodeAndName
        {
            get
            {
                return string.Format("{0} - {1}", Code, Name);
            }
        }

        public decimal SalesShare { get; set; }

        public decimal SpaceShare { get; set; }

        public decimal TheoreticalMargin { get; set; }

        public decimal NormalizeUnits
        {
            get
            {
                return this.Coverage > 0 ? (1m / this.Coverage) * this.Units : 0;
            }
        }

        public decimal NormalizeSales
        {
            get
            {
                return this.Coverage > 0 ? (1m / this.Coverage) * this.Sales : 0;
            }
        }

        public decimal GapSalesSpace
        {
            get { return this.SalesShare - this.SpaceShare; }
        }

        public decimal? LinearSpaceMts
        {
            get { return this.Width * this.Facings / 100m; }
        }

        public string Status
        {
            get 
            {
                if (Type == "COMP" || Type == "HAWK")
                {
                    return "Components";
                }
                else if (IsNew)
                {
                    return "New";
                }
                else if (IsDeletedRangeReview && !IsNew && !IsDelisted && Source == "ArticleMaster")
                {
                    return "CleanUp";
                }
                else if (IsDelisted && Source == "ArticleMaster")
                {
                    return "Only PY";
                }
                else if (!IsDelisted && !IsNew && !IsDeletedRangeReview && Source == "ArticleMaster")
                {
                    return "Active";
                }
                else if (IsDelisted)
                {
                    return "Delisted";
                }
                return string.Empty;
            }
        }

        public Dictionary<DateTime, string> SalesByDate { get; set; }

        public Dictionary<string, string> SpacesByLocation { get; set; }

        public string Planograms { get; set; }

        protected override List<ValidationBase> SetValidations()
        {
            List<ValidationBase> inputValidations = (new ArticleInputValidations(this)).CreateValidations();

            return inputValidations;
        }
    }

    public enum ArticleNumericColumns
    {
        Size = 0,
        Height = 1,
        Width = 2,
        Facings = 3
    }
}
